<script setup>
import { ref } from 'vue'
const show = ref(true)
const props = defineProps({
  type: {
    type: String,
    default: 'success',
  },
  className: {
    type: String,
    default: '',
  },
  title: {
    type: String,
    default: '',
  },
  content: {
    type: String,
    default: '',
  },
  showConfirm: {
    type: Boolean,
    default: true,
  },
  confirmText: {
    type: String,
    default: '确定',
  },
  showCancel: {
    type: Boolean,
    default: true,
  },
  cancelText: {
    type: String,
    default: '取消',
  },
  confirmFun: {
    type: Function,
    default: () => {},
  },
  cancelFun: {
    type: Function,
  },
  showClose: {
    type: Boolean,
    default: true,
  },
  closeFun: {
    type: Function,
  },
})

function handleClose() {
  typeof props.closeFun === 'function' && props.closeFun()
  show.value = false
}

function handleCancel() {
  typeof props.cancelFun === 'function' && props.cancelFun()
  show.value = false
}

function handleConfirm() {
  typeof props.confirmFun === 'function' && props.confirmFun()
}
</script>

<template>
  <div v-if="show" class="toast-cover" :class="props.className">
    <div class="toast-box">
      <i
        v-if="showClose"
        class="iconfont icon-danchuangguanbiicon"
        @click="handleClose"
      ></i>
      <template v-if="type !== 'none'">
        <i v-if="type === 'success'" class="iconfont icon-gouxuanicon"></i>
        <i v-else class="iconfont icon-gantanhaoicon"></i>
      </template>
      <div class="toast-title fz-14">{{ title }}</div>
      <div class="toast-content fz-12">{{ content }}</div>
      <div class="toast-btn">
        <button v-if="showCancel" class="toast-cancel" @click="handleCancel">
          {{ cancelText }}
        </button>
        <button v-if="showConfirm" class="toast-confirm" @click="handleConfirm">
          {{ confirmText }}
        </button>
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
.toast-cover {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  z-index: 99;
  @include fcc;
  .toast-box {
    width: 2.75rem;
    background: #fff;
    position: relative;
    text-align: center;
    padding: 0.3rem 0 0.25rem;
    border-radius: 0.08rem;
    .icon-danchuangguanbiicon {
      position: absolute;
      right: 0.1rem;
      top: 0.1rem;
    }
    .icon-gouxuanicon {
      color: #3f84f3;
      font-size: 0.95rem;
    }
    .icon-gantanhaoicon {
      color: #fc653f;
      font-size: 0.95rem;
    }
    .toast-title {
      color: #222;
      padding: 0 0.25rem;
      margin: 0.18rem 0 0.04rem;
    }
    .toast-content {
      color: #999999;
      padding: 0 0.25rem;
      max-height: 50vh;
      overflow: auto;
      word-wrap: break-word;
    }
    .toast-btn {
      @include fcc;
      margin-top: 0.3rem;
      padding-left: 0.2rem;
      button {
        flex: 1;
        max-width: 1.65rem;
        height: 0.4rem;
        border: none;
        border-radius: 0.2rem;
        margin-right: 0.2rem;
      }
      .toast-cancel {
        background: #f4f4f4;
        color: #666666;
      }
      .toast-confirm {
        background: #3f84f3;
        color: #fff;
      }
    }
  }
}
</style>
